# bubble sort
def bubble(nums):
  '''
  冒泡排序法
  :param nums: 待排序数据列表
  :return: 列表对象，排好序的数据列表
  '''
  for j in range(len(nums) - 2):
    flag = False
    for i in range(len(nums) - 1):
      if nums[i] > nums[i+1] :
        nums[i], nums[i + 1] = nums[i + 1], nums[i]
        flag = True
    if not flag:
      break
  return nums


if __name__ == '__main__':
  num_list = []
  print("请输入多个正整数，以空格分隔：")
  # 方法一：可在同一行输入多个正整数，以空格分隔
  str = input()
  numbers = str.split()
  for i in range(len(numbers)):
    num_list.append(int(numbers[i]))
  print("最终排好序的结果是：")
  print(bubble(num_list))

  # 方法二，采用while True，以符号结尾跳出输入循环，缺点是只能竖向输入
  # while True:
  #   num = input()
  #
  #   if num.isdigit():
  #     num = int(num)
  #     num_list.append(num)
  #   elif num == "#":
  #     break
  # print(bubble(num_list))
